import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import sass from 'sass-embedded'

export default defineConfig({
  //代理
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:5173',
        //开启代理，允许跨域
        changeOrigin: true,
        // 识别api替换''空字符串 取BASE_URL
        rewrite: path => path.replace(/^\/api/, '')
      },
      // 配置多个代理 防止项目中2个接口地址
      '/api1': {
        target: 'http://localhost:8081',
        changeOrigin: true,
      }
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        implementation: sass
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  plugins: [vue()],
})
